from typing import Optional
from pydantic import BaseModel, EmailStr
from datetime import datetime

# 共享属性
class UserBase(BaseModel):
    email: Optional[EmailStr] = None
    username: Optional[str] = None
    is_active: Optional[bool] = True
    is_superuser: bool = False

# 创建用户时需要的属性
class UserCreate(UserBase):
    email: EmailStr
    username: str
    password: str

# 更新用户时可以更新的属性
class UserUpdate(UserBase):
    password: Optional[str] = None

# API响应中的用户信息
class User(UserBase):
    id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        orm_mode = True

# 登录请求
class UserLogin(BaseModel):
    username: str
    password: str
    captcha: str

# 密码重置
class PasswordReset(BaseModel):
    email: EmailStr

# 密码修改
class PasswordChange(BaseModel):
    old_password: str
    new_password: str

# 数据库中的用户模型
class UserInDB(User):
    hashed_password: str